Skip to content

Fix unix-ffi/re: Fix OverflowError in re.groups().#1089

Merged
dpgeorge merged 2 commits intomicropython:masterfrom
Josverl:fix_unixffe_re
Mar 19, 2026
Merged

Fix unix-ffi/re: Fix OverflowError in re.groups().#1089
dpgeorge merged 2 commits intomicropython:masterfrom
Josverl:fix_unixffe_re

Conversation

@Josverl
Copy link
Contributor

@Josverl Josverl commented Mar 1, 2026

Adjust the re.groups() methods to properly handle the PCRE2_UNSET value for unmatched optional groups.
This change prevents OverflowError when calling groups() on a match with no content.

The return matches CPython's.

A test case for an empty string match has been added to verify expected behavior.

Fixes micropython/micropython#18877

@dpgeorge
Copy link
Member

dpgeorge commented Mar 2, 2026

Thanks for this, the fix looks good!

Can I suggest adding more tests, ie:

m = re.match(r"(.)?", "")
assert m.group() == ""
assert m.group(0, 1) == ("", None)
assert m.groups() == (None,)
assert m.groups("default") == ("default",)

That will test group() behaviour and default value.

@Josverl
Copy link
Contributor Author

Josverl commented Mar 2, 2026

Sure, happy to add.

I noticed that the readme mentions 'unsupported' for the unix-ffi folder, and I do not think these modules are included in CI testing either.

So AFIKT the tests need to be run manually, so still useful for validating.

@dpgeorge
Copy link
Member

dpgeorge commented Mar 2, 2026

I do not think these modules are included in CI testing either.

I think it is run under CI, see tools/ci.sh:ci_package_tests_run.

@dpgeorge
Copy link
Member

@Josverl are you able to add those few tests I list above?

@Josverl
Copy link
Contributor Author

Josverl commented Mar 19, 2026

sorry , got sidetracked.
You are correct that the tests are run in CI.
Added the tests as requested.

Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Josverl added 2 commits March 19, 2026 22:32
Adjust the re.groups() methods to properly handle the PCRE2_UNSET value for
unmatched optional groups.

This change prevents OverflowError when calling groups() on a match with no
content.

The return matches CPython's.

Fixes: micropython/micropython#18877

Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
@dpgeorge dpgeorge merged commit 47fec41 into micropython:master Mar 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

re groups() raises OverflowError for unmatched optional groups

2 participants